#include <cstdio>
#include <map>
#include <tuple>
int n;
long long Mod;
std::map<std::tuple<int, int, int>, long long> mem;
long long calc(int n, int last, int take)
{
    if (n == 0)
    {
        return 1;
    }
    if (last == 0)
    {
        return 0;
    }
    if (mem.count({n, last, take}))
    {
        return mem[{n, last, take}];
    }
    if (take == 0)
    {
        return mem[{n, last, take}] = calc(n - 1, last, 1) % Mod;
    }
    else
    {
        return mem[{n, last, take}] =
                   (calc(n, take - 1, 0) + (n >= 2 && take + 1 <= last ? calc(n - 2, last, take + 1) : 0)) % Mod;
    }
}
void solve()
{
    scanf("%d", &n);
    printf("%lld\n", calc(n, 2e5, 0) % Mod);
}
int main()
{
    freopen("moon.in", "r", stdin);
    freopen("moon.out", "w", stdout);
    int t;
    scanf("%d%lld", &t, &Mod);
    for (int i = 1; i <= t; i++)
    {
        solve();
    }
    return 0;
}